﻿namespace Forms
{
    using Forms.My;
    using Forms.My.Resources;

    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;

    using System.Drawing;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;

    [DesignerGenerated]
    public class frmAbloesen : Form
    {

        private List<AbloeseData> AbloeseListe;
        private string ActualKonto;
        private int ActualStep;
        private bool AlwaysVisible;
        private IContainer components;
        private int ErrBridgeCounter;

        public frmAbloesen()
        {
            base.KeyDown += new KeyEventHandler(this.frmAbloesen_KeyDown);
            base.Load += new EventHandler(this.frmAbloesen_Load);
            base.FormClosing += new FormClosingEventHandler(this.frmAbloesen_FormClosing);



            this.AbloeseListe = new List<AbloeseData>();
            this.ErrBridgeCounter = 0;
            this.InitializeComponent();
            
          
        
        }

        private void AbortButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        [DebuggerNonUserCode]
        protected override void Dispose(bool disposing)
        {
            try
            {
                

                if (disposing && (this.components != null))
                {
                    this.components.Dispose();
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }

        private void frmAbloesen_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.TheTimer.Enabled = false;
            if (this.webB != null)
            {
                this.webB.Navigating -= this.webB_Starting_Navigation;
            }
            if (this.TheTimer != null)
            {
                this.TheTimer.Tick -= this.TheTimer_Tick;
            }
            if (this.AbortButton != null)
            {
                this.AbortButton.Click += this.AbortButton_Click;
            }

            foreach (AbloeseData data in this.AbloeseListe)
            {
                DataRow[] rowArray = MyProject.Forms.Main.cs.dsBMW.TAB_Auswertung.Select("FGST_Nr = '" + data.FGST + "'");
                if ((rowArray.Length > 0) && data.Done)
                {
                    string str = "";
                    if (rowArray[0]["Bemerkung"] != DBNull.Value)
                    {
                        str = Conversions.ToString(rowArray[0]["Bemerkung"]);
                    }
                    if (data.Fehler)
                    {
                        if (str != "")
                        {
                            rowArray[0]["Bemerkung"] = "Fehler beim Ablösen / " + str;
                        }
                        else
                        {
                            rowArray[0]["Bemerkung"] = "Fehler beim Ablösen";
                        }
                    }
                    else
                    {
                        rowArray[0]["Abgeloest"] = true;
                        if (str != "")
                        {
                            rowArray[0]["Bemerkung"] = "abgelöst / " + str;
                        }
                        else
                        {
                            rowArray[0]["Bemerkung"] = "abgelöst";
                        }
                        DatenschemaBMW.TAB_HistorieRow row = (DatenschemaBMW.TAB_HistorieRow) MyProject.Forms.Main.cs.Table_Historie.NewRow();
                        DatenschemaBMW.TAB_HistorieRow row2 = row;
                        row2.FGST_Nr = data.FGST;
                        row2.Name = data.Name;
                        row2.Kredit_Nr = data.KreditNum;
                        row2.RE_Dat_VK = data.RGDatum;
                        row2.RE_Nr_VK = data.RGNr;
                        row2.Kunden_Nr = data.KundenNr;
                        row2.Abloese_Betrag = new decimal(data.KreditSaldo);
                        row2.Abloese_Datum = Conversions.ToDate(Strings.Format(DateAndTime.Now, "dd.MM.yyyy"));
                        row2 = null;
                        MyProject.Forms.Main.cs.Table_Historie.Rows.Add(row);
                    }
                }
            }
            MyProject.Forms.Main.cs.Table_Historie.AcceptChanges();
        }

        private void frmAbloesen_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control & (e.KeyCode == Keys.W))
            {
                if (this.AlwaysVisible)
                {
                    this.AlwaysVisible = false;
                    this.webB.Visible = false;
                    this.lstAbloesen.Visible = true;
                    this.txtDebug.Visible = false;
                }
                else
                {
                    this.AlwaysVisible = true;
                    this.webB.Visible = true;
                    this.lstAbloesen.Visible = false;
                    this.txtDebug.Visible = true;
                }
            }
        }

        private void frmAbloesen_Load(object sender, EventArgs e)
        {
            this.TheTimer.Tick += this.TheTimer_Tick;
            this.webB.Navigating += this.webB_Starting_Navigation;
            this.AbortButton.Click += this.AbortButton_Click;

            this.ActualStep = 1;

            this.TheTimer.Enabled = true;
            this.webB.DocumentText = "";
            this.AbortButton.Text = "Abbrechen";
            this.txtStatus.Text = "";
            DataRow[] rowArray = MyProject.Forms.Main.cs.Table_Finanzierungsarten.Select("FA_Abloesen = 1");
            this.AbloeseListe.Clear();
            this.lstAbloesen.Clear();
            this.lstAbloesen.Columns.Add("Kredit-Nr.", 100, HorizontalAlignment.Left);
            this.lstAbloesen.Columns.Add("Konto", 100, HorizontalAlignment.Left);
            this.lstAbloesen.Columns.Add("FGST-Nr.", 100, HorizontalAlignment.Left);
            this.lstAbloesen.Columns.Add("Kredit-Saldo", 100, HorizontalAlignment.Right);
            this.lstAbloesen.Columns.Add("Status", 200, HorizontalAlignment.Left);
            foreach (DataRow row in rowArray)
            {
                foreach (DataRow row2 in MyProject.Forms.Main.cs.Table_Auswertung.Select("FA_ID = '" + row["FA_ID"].ToString() + "' And Abgeloest=False"))
                {
                    DataRow[] rowArray2 = MyProject.Forms.Main.cs.Table_BMWBankHeaders.Select("BMW_Header_ID = '" + row2["BMW_Header_ID"].ToString() + "'");
                    if (Operators.ConditionalCompareObjectEqual(rowArray2[0]["Typ"], "BMW", false))
                    {
                        AbloeseData data = new AbloeseData();
                        data.Konto = Conversions.ToString(rowArray2[0]["Deb_Kto_Nr"]);
                        data.FGST = Conversions.ToString(row2["FGST_Nr"]);
                        data.KreditNum = Conversions.ToString(row2["Kredit_Nr"]);
                        data.KreditSaldo = Conversions.ToDouble(row2["Kredit_Saldo"]);
                        data.Name = Conversions.ToString(row2["Name1"]);
                        data.KundenNr = Conversions.ToString(row2["Kunden_Nr"]);
                        data.RGDatum = Conversions.ToString(row2["RE_Dat_VK"]);
                        data.RGNr = Conversions.ToString(row2["RE_Nr_Vk"]);
                        data.Fehler = false;
                        data.Done = false;
                        this.AbloeseListe.Add(data);
                        ListViewItem item = new ListViewItem(data.KreditNum);
                        item.UseItemStyleForSubItems = false;
                        item.SubItems.Add(data.Konto);
                        item.SubItems.Add(data.FGST);
                        item.SubItems.Add(Strings.Format(data.KreditSaldo, "###,###,##0.00"));
                        item.SubItems.Add("");
                        this.lstAbloesen.Items.Add(item);
                    }
                }
            }
            if (this.AbloeseListe.Count == 0)
            {
                Interaction.MsgBox("Keine Fahrzeuge zum Ablösen vorhanden!", MsgBoxStyle.Exclamation, "Hinweis");
                this.Close();
            }
        }

        private bool IdentifySite(string[] LinkelementsText)
        {
            HtmlElementCollection elementsByTagName = this.webB.Document.GetElementsByTagName("a");
            if ((elementsByTagName != null) && (elementsByTagName.Count > 0))
            {
                int num3 = LinkelementsText.Length - 1;
                for (int i = 0; i <= num3; i++)
                {
                    bool flag3 = false;
                    int num4 = elementsByTagName.Count - 1;
                    for (int j = 0; j <= num4; j++)
                    {
                        if ((elementsByTagName[j].InnerText != null) && (elementsByTagName[j].InnerText.Trim() == LinkelementsText[i].Trim()))
                        {
                            flag3 = true;
                            break;
                        }
                    }
                    if (!flag3)
                    {
                        return false;
                    }
                }
            }
            return true;
        }

        private object IdentifySite(string TagName, string TagAttribute, string TagValue)
        {
            object obj2;
            try
            {
                if (this.webB.Document.GetElementById(TagName).GetAttribute(TagAttribute) == TagValue)
                {
                    return true;
                }
                obj2 = false;
            }
            catch (NullReferenceException exception1)
            {
                ProjectData.SetProjectError(exception1);
                NullReferenceException exception = exception1;
                obj2 = false;
                ProjectData.ClearProjectError();
            }
            return obj2;
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
            this.components = new Container();
            this.AbortButton = new Button();
            this.webB = new WebBrowser();
            this.txtStatus = new Label();
            this.TheTimer = new Timer(this.components);
            this.ProgressImage = new ProgressBar();
            this.lstAbloesen = new ListView();
            this.txtDebug = new Label();
            this.SuspendLayout();
            this.AbortButton.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;

            this.AbortButton.Location = new Point(0x368, 0x273);
            this.AbortButton.Name = "AbortButton";

            this.AbortButton.Size = new Size(100, 0x19);
            this.AbortButton.TabIndex = 0;
            this.AbortButton.Text = "Abbrechen";
            this.AbortButton.UseVisualStyleBackColor = true;
            this.webB.AllowWebBrowserDrop = false;
            this.webB.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
            this.webB.IsWebBrowserContextMenuEnabled = false;
            this.webB.Location = new Point(12,12);
            this.webB.MinimumSize = new Size(20, 20);
            this.webB.Name = "webB";
            this.webB.ScriptErrorsSuppressed = true;
            this.webB.Size = new Size(960, 0x250);
            this.webB.TabIndex = 1;
            this.webB.WebBrowserShortcutsEnabled = false;
            this.txtStatus.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom;
            this.txtStatus.Location = new Point(12, 0x279);
            this.txtStatus.Name = "txtStatus";
            this.txtStatus.Size = new Size(0x356, 0x12);
            this.txtStatus.TabIndex = 3;
            this.txtStatus.TextAlign = ContentAlignment.MiddleCenter;
            this.TheTimer.Interval = 0x3e8;
            this.ProgressImage.Location = new Point(12, 610);
            this.ProgressImage.Name = "ProgressImage";
            this.ProgressImage.Size = new Size(0x356, 20);
            this.ProgressImage.Style = ProgressBarStyle.Marquee;
            this.ProgressImage.TabIndex = 4;
            this.ProgressImage.TabStop = false;
            this.lstAbloesen.AllowColumnReorder = true;
            this.lstAbloesen.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
            this.lstAbloesen.Location = new Point(12, 12);
            this.lstAbloesen.Name = "lstAbloesen";
            this.lstAbloesen.Size = new Size(960, 0x250);
            this.lstAbloesen.Sorting = SortOrder.Ascending;
            this.lstAbloesen.TabIndex = 5;
            this.lstAbloesen.UseCompatibleStateImageBehavior = false;
            this.lstAbloesen.View = View.Details;
            this.txtDebug.AutoSize = true;
            this.txtDebug.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Bold, GraphicsUnit.Point, 0);
            this.txtDebug.ForeColor = Color.FromArgb(0xff, 0x80, 0x80);
            this.txtDebug.Location = new Point(12, 0x27c);
            this.txtDebug.Name = "txtDebug";
            this.txtDebug.Size = new Size(0x75, 13);
            this.txtDebug.TabIndex = 6;
            this.txtDebug.Text = "Debug-Modus aktiv";
            this.txtDebug.Visible = false;
            this.AutoScaleDimensions = new SizeF(6f, 13f);
            this.ClientSize = new Size(0x3d8, 0x298);
            this.Controls.Add(this.txtDebug);
            this.Controls.Add(this.lstAbloesen);
            this.Controls.Add(this.ProgressImage);
            this.Controls.Add(this.txtStatus);
            this.Controls.Add(this.webB);
            this.Controls.Add(this.AbortButton);
            this.KeyPreview = true;
            this.Name = "frmAbloesen";
            this.Text = "Ablösen";
            this.ResumeLayout(false);
            this.PerformLayout();
        }

        private void SetListViewItem(string KreditNum, string Status, int color)
        {
            IEnumerator enumerator = this.lstAbloesen.Items.GetEnumerator();
            
            try
            {
                while (enumerator.MoveNext())
                {
                    ListViewItem current = (ListViewItem) enumerator.Current;
                    if (current.Text == KreditNum)
                    {
                        current.SubItems[4].Text = Status;
                        switch (color)
                        {
                            case 0:
                                current.SubItems[4].BackColor = Color.White;
                                break;

                            case 1:
                                current.SubItems[4].BackColor = Color.YellowGreen;
                                break;

                            case 2:
                                current.SubItems[4].BackColor = Color.LightCoral;
                                break;
                        }
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        private void ShowUnexpectedSiteError()
        {
            string str;
            this.TheTimer.Enabled = false;
            if (!this.AlwaysVisible)
            {
                str = "Eine Seite konnte nicht geladen werden oder eine Seite im unbekannten Format wurde geladen!\nSoll der Vorgang neu gestartet werden und ein erneuter Verbindungsversuch durchgeführt werden?";
            }
            else
            {
                str = "Detalierter Fehlerbericht nicht möglich. Neuer Versuch?";
            }
            if (Interaction.MsgBox(str, MsgBoxStyle.Exclamation | MsgBoxStyle.YesNo, "Seitenladefehler") == MsgBoxResult.Yes)
            {
                this.ActualStep = 1;
                this.TheTimer.Enabled = true;
            }
            else
            {
                this.ActualStep = 0;
                this.Close();
            }
        }

        private void ShowUnexpectedSiteError(NullReferenceException ex)
        {
            string str;
            this.TheTimer.Enabled = false;
            if (!this.AlwaysVisible)
            {
                str = "Eine Seite konnte nicht geladen werden oder eine Seite im unbekannten Format wurde geladen!\nSoll der Vorgang neu gestartet werden und ein erneuter Verbindungsversuch durchgeführt werden?";
            }
            else
            {
                str = "Detalierter Fehlerbericht: \n" + ex.Source + " verursachte die Ausnahme.\n\n" + ex.StackTrace;
            }
            if (Interaction.MsgBox(str, MsgBoxStyle.Exclamation | MsgBoxStyle.YesNo, "Seitenladefehler") == MsgBoxResult.Yes)
            {
                this.ActualStep = 1;
                this.TheTimer.Enabled = true;
            }
            else
            {
                this.ActualStep = 0;
                this.Close();
            }
        }

        private void TheTimer_Tick(object sender, EventArgs e)
        {
            if ((!this.webB.IsBusy & (this.webB.ReadyState == WebBrowserReadyState.Complete)) | ((this.webB.ReadyState == WebBrowserReadyState.Uninitialized) & (this.ActualStep == 1)))
            {
                switch (this.ActualStep)
                {
                    case 1:
                        this.lstAbloesen.Visible = false;
                        this.webB.Visible = true;
                        this.txtStatus.Font = new Font(FontFamily.GenericSansSerif, 10f, FontStyle.Regular);
                        this.txtStatus.Text = "Lade Login-Seite...";
                        this.webB.ScriptErrorsSuppressed = true;
                        this.webB.Navigate(new Uri("https://banking.bmwbank.de/haendler"));
                        this.ActualStep++;
                        break;

                    case 2:
                        if (!Conversions.ToBoolean(this.IdentifySite("PWChange", "method", "post")))
                        {
                            this.ShowUnexpectedSiteError();
                            break;
                        }
                        this.ActualStep++;
                        this.txtStatus.Font = new Font(FontFamily.GenericSansSerif, 10f, FontStyle.Bold);
                        this.txtStatus.Text = "Bitte geben Sie Ihre BMW-Bank-Zugangsdaten ein und klicken Sie auf 'Anmelden'!";
                        this.webB.Visible = true;
                        this.ProgressImage.Visible = false;
                        this.lstAbloesen.Visible = false;
                        break;

                    case 3:
                        try
                        {
                            HtmlElementCollection elementsByTagName = this.webB.Document.All["leftNavigation"].GetElementsByTagName("a");
                            bool flag = false;
                            int num11 = elementsByTagName.Count - 1;
                            int num = 0;
                            while (num <= num11)
                            {
                                if (elementsByTagName[num].InnerText == "Vertragsmanagement")
                                {
                                    flag = true;
                                    break;
                                }
                                num++;
                            }
                            if (flag)
                            {
                                this.ActualStep++;
                                elementsByTagName[num].InvokeMember("click");
                            }
                            else if (!Conversions.ToBoolean(this.IdentifySite("PWChange", "method", "post")))
                            {
                                this.ShowUnexpectedSiteError();
                            }
                        }
                        catch (NullReferenceException exception1)
                        {
                            ProjectData.SetProjectError(exception1);
                            NullReferenceException ex = exception1;
                            if (!Conversions.ToBoolean(this.IdentifySite("PWChange", "method", "post")))
                            {
                                this.ShowUnexpectedSiteError(ex);
                            }
                            ProjectData.ClearProjectError();
                        }
                        break;

                    case 4:
                        try
                        {
                            HtmlElementCollection elements2 = this.webB.Document.All["leftNavigation"].GetElementsByTagName("a");
                            bool flag2 = false;
                            int num12 = elements2.Count - 1;
                            int num2 = 0;
                            while (num2 <= num12)
                            {
                                if (elements2[num2].InnerText == "Vertragsübersicht")
                                {
                                    flag2 = true;
                                    break;
                                }
                                num2++;
                            }
                            if (flag2)
                            {
                                this.ActualStep++;
                                elements2[num2].InvokeMember("click");
                            }
                            else if (!Conversions.ToBoolean(this.IdentifySite("PWChange", "method", "post")))
                            {
                                this.ShowUnexpectedSiteError();
                            }
                        }
                        catch (NullReferenceException exception7)
                        {
                            ProjectData.SetProjectError(exception7);
                            NullReferenceException exception2 = exception7;
                            if (!Conversions.ToBoolean(this.IdentifySite("PWChange", "method", "post")))
                            {
                                this.ShowUnexpectedSiteError(exception2);
                            }
                            ProjectData.ClearProjectError();
                        }
                        break;

                    case 5:
                    {
                        if (!this.AlwaysVisible)
                        {
                            this.webB.Visible = false;
                            this.lstAbloesen.Visible = true;
                        }
                        else
                        {
                            this.webB.Visible = true;
                            this.lstAbloesen.Visible = false;
                        }
                        this.ActualKonto = "";
                        int num13 = this.AbloeseListe.Count - 1;
                        for (int i = 0; i <= num13; i++)
                        {
                            if (!this.AbloeseListe[i].Fehler & !this.AbloeseListe[i].Done)
                            {
                                this.ActualKonto = this.AbloeseListe[i].Konto;
                                break;
                            }
                        }
                        if (this.ActualKonto == "")
                        {
                            this.ActualStep = 10;
                            return;
                        }
                        try
                        {
                            this.txtStatus.Font = new Font(FontFamily.GenericSansSerif, 10f, FontStyle.Regular);
                            this.txtStatus.Text = "Rufe Kontoauszüge für Konto " + this.ActualKonto + " ab ...";
                            HtmlElementCollection elements3 = this.webB.Document.All["slDebitorAccount"].GetElementsByTagName("option");
                            bool flag3 = false;
                            int num14 = elements3.Count - 1;
                            int num4 = 0;
                            while (num4 <= num14)
                            {
                                if (elements3[num4].InnerText == this.ActualKonto)
                                {
                                    flag3 = true;
                                    break;
                                }
                                num4++;
                            }
                            if (!flag3)
                            {
                                foreach (AbloeseData data in this.AbloeseListe)
                                {
                                    if (data.Konto == this.ActualKonto)
                                    {
                                        data.Fehler = true;
                                        this.SetListViewItem(data.KreditNum, "Konto nicht gefunden!", 2);
                                    }
                                }
                            }
                            else
                            {
                                this.webB.Document.All["slDebitorAccount"].SetAttribute("value", elements3[num4].GetAttribute("value"));
                                this.webB.Document.All["slTablePageSize"].SetAttribute("value", "4");
                                HtmlElementCollection elements4 = this.webB.Document.GetElementsByTagName("a");
                                int num15 = elements4.Count - 1;
                                for (num4 = 0; num4 <= num15; num4++)
                                {
                                    if (elements4[num4].InnerText == "Verträge anzeigen")
                                    {
                                        elements4[num4].InvokeMember("click");
                                        this.ActualStep++;
                                        return;
                                    }
                                }
                            }
                        }
                        catch (NullReferenceException exception8)
                        {
                            ProjectData.SetProjectError(exception8);
                            NullReferenceException exception3 = exception8;
                            this.ShowUnexpectedSiteError(exception3);
                            ProjectData.ClearProjectError();
                        }
                        return;
                    }
                    case 6:
                        try
                        {
                           
                            HtmlElementCollection elements5 = this.webB.Document.GetElementsByTagName("a");
                            bool flag4 = false;
                            int num5 = -1;
                            if (this.webB.DocumentText.Contains("Verarbeitungsfehler") & this.webB.DocumentText.Contains("??????"))
                            {
                                if (this.ErrBridgeCounter < 3)
                                {
                                    this.ErrBridgeCounter++;
                                    elements5 = this.webB.Document.All["leftNavigation"].GetElementsByTagName("a");
                                    flag4 = false;
                                    int num16 = elements5.Count - 1;
                                    for (num5 = 0; num5 <= num16; num5++)
                                    {
                                        if (elements5[num5].InnerText == "Vertragsübersicht")
                                        {
                                            this.txtStatus.Font = new Font(FontFamily.GenericSansSerif, 10f, FontStyle.Regular);
                                            this.txtStatus.Text = "Erneuter Versuch: Rufe Kontoauszüge für Konto " + this.ActualKonto + " ab ...";
                                            flag4 = true;
                                            elements5[num5].InvokeMember("click");
                                            break;
                                        }
                                    }
                                }
                                if ((this.ErrBridgeCounter > 3) | !flag4)
                                {
                                    Interaction.MsgBox("Fehler beim Abrufen der Kontodaten.\r\nVorgang wird abgebrochen.", MsgBoxStyle.Critical, "Schwerer Fehler");
                                    this.TheTimer.Enabled = false;
                                    this.Close();
                                    break;
                                }
                            }

                            HtmlElementCollection elements6 = this.webB.Document.GetElementsByTagName("tr");
                            IEnumerator enumerator = enumerator = elements6.GetEnumerator();
                            try
                            {
                                
                                while (enumerator.MoveNext())
                                {
                                    HtmlElement current = (HtmlElement) enumerator.Current;
                                
                                    IEnumerator enumerator3 = current.Children.GetEnumerator();
                                    string str3 = "";
                                    string str4 = "";
                                    string str2 = "";
                                    string id = "";
                                    try
                                    {
                                        while (enumerator3.MoveNext())
                                        {
                                            HtmlElement element2 = (HtmlElement) enumerator3.Current;
                                            if ((element2.Children.Count > 0) && (element2.Children[0].GetAttribute("type") == "checkbox"))
                                            {
                                                id = element2.FirstChild.GetAttribute("id");
                                            }
                                            string attribute = element2.GetAttribute("headers");
                                            if (attribute == "searchresult:creditnumber")
                                            {
                                                str3 = element2.InnerText.Trim();
                                            }
                                            else
                                            {
                                                if (attribute == "searchresult:chassisnumber")
                                                {
                                                    str2 = element2.InnerText.Trim();
                                                    continue;
                                                }
                                                if (attribute == "searchresult:creditsaldo")
                                                {
                                                    str4 = element2.InnerText.Replace("€", "").Trim();
                                                }
                                            }
                                        }
                                    }
                                    finally
                                    {
                                        if (enumerator3 is IDisposable)
                                        {
                                            (enumerator3 as IDisposable).Dispose();
                                        }
                                    }
                                    if ((((id != "") & (str2 != "")) & (str3 != "")) & (str4 != ""))
                                    {
                                        List<AbloeseData>.Enumerator enumerator4 = this.AbloeseListe.GetEnumerator();
                                        try
                                        {
                                            
                                            while (enumerator4.MoveNext())
                                            {
                                                AbloeseData data2 = enumerator4.Current;
                                                if ((((data2.Konto == this.ActualKonto) & (data2.KreditNum == str3)) & !data2.Done) & !data2.Fehler)
                                                {
                                                    if ((data2.FGST != str2) | (data2.KreditSaldo != Conversions.ToDouble(str4)))
                                                    {
                                                        if (data2.FGST != str2)
                                                        {
                                                            this.SetListViewItem(data2.KreditNum, "FGST-Nr ist falsch!", 2);
                                                        }
                                                        if (data2.KreditSaldo != Conversions.ToDouble(str4))
                                                        {
                                                            this.SetListViewItem(data2.KreditNum, "Salden stimmen nicht überein!", 2);
                                                        }
                                                        data2.Fehler = true;
                                                    }
                                                    else
                                                    {
                                                        this.txtStatus.Font = new Font(FontFamily.GenericSansSerif, 10f, FontStyle.Regular);
                                                        this.txtStatus.Text = "Ablösen FGST-Nr.: " + str2 + " ab ...";
                                                        this.webB.Document.GetElementById(id).SetAttribute("checked", "checked");
                                                        data2.Done = true;
                                                        this.SetListViewItem(data2.KreditNum, "Ok", 1);
                                                    }
                                                    break;
                                                }
                                            }
                                            continue;
                                        }
                                        finally
                                        {
                                            enumerator4.Dispose();
                                        }
                                    }
                                }
                            }
                            finally
                            {
                                if (enumerator is IDisposable)
                                {
                                    (enumerator as IDisposable).Dispose();
                                }
                            }
                            this.txtStatus.Text = "Ablösen für Konto " + this.ActualKonto + " abgeschlossen.";
                            foreach (AbloeseData data3 in this.AbloeseListe)
                            {
                                if (((data3.Konto == this.ActualKonto) & !data3.Done) & !data3.Fehler)
                                {
                                    data3.Fehler = true;
                                    this.SetListViewItem(data3.KreditNum, "Fahrzeug nicht gefunden!", 2);
                                }
                            }
                            int num17 = elements5.Count - 1;
                            for (num5 = 0; num5 <= num17; num5++)
                            {
                                if (elements5[num5].InnerText == "Auswählen")
                                {
                                    this.ActualStep++;
                                    elements5[num5].InvokeMember("click");
                                    break;
                                }
                            }
                        }
                        catch (NullReferenceException exception9)
                        {
                            ProjectData.SetProjectError(exception9);
                            NullReferenceException exception4 = exception9;
                            this.ShowUnexpectedSiteError(exception4);
                            ProjectData.ClearProjectError();
                        }
                        break;

                    case 7:
                        try
                        {
                            HtmlElementCollection elements7 = this.webB.Document.GetElementsByTagName("a");
                            bool flag5 = false;
                            int num18 = elements7.Count - 1;
                            for (int j = 0; j <= num18; j++)
                            {
                                if (elements7[j].InnerText == "Ablösung für Markierte")
                                {
                                    this.ActualStep++;
                                    flag5 = true;
                                    elements7[j].InvokeMember("click");
                                    break;
                                }
                            }
                            if (!flag5)
                            {
                                this.ShowUnexpectedSiteError();
                            }
                        }
                        catch (NullReferenceException exception10)
                        {
                            ProjectData.SetProjectError(exception10);
                            NullReferenceException exception5 = exception10;
                            this.ShowUnexpectedSiteError(exception5);
                            ProjectData.ClearProjectError();
                        }
                        break;

                    case 8:
                    {
                        string[] linkelementsText = new string[] { "In den TA-Pool stellen", "Ablösung einreichen", "Ablösung ändern" };
                        if (this.IdentifySite(linkelementsText))
                        {
                            if (!MySettings.MySettingsProperty.UseTAPool)
                            {
                                this.ActualStep++;
                                this.txtStatus.Font = new Font(FontFamily.GenericSansSerif, 10f, FontStyle.Bold);
                                this.txtStatus.Text = "Bitte bestätigen Sie den Ablösevorgang indem Sie auf 'Ablösung einreichen' klicken!";
                                this.webB.Visible = true;
                                this.ProgressImage.Visible = false;
                                this.lstAbloesen.Visible = false;
                            }
                            else
                            {
                                HtmlElementCollection elements8 = this.webB.Document.GetElementsByTagName("a");
                                int num19 = elements8.Count - 1;
                                for (int k = 0; k <= num19; k++)
                                {
                                    if (elements8[k].InnerText == "In den TA-Pool stellen")
                                    {
                                        this.ActualStep++;
                                        elements8[k].InvokeMember("click");
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            this.ShowUnexpectedSiteError();
                        }
                        break;
                    }
                    case 9:
                    {
                        if (MySettings.MySettingsProperty.UseTAPool)
                        {
                            string[] strArray3 = new string[] { "Überweisung anlegen", "Ablösung anlegen", "Kfz-Briefanforderung erfassen" };
                            if (this.IdentifySite(strArray3))
                            {
                                this.ActualStep++;
                            }
                            else
                            {
                                this.ShowUnexpectedSiteError();
                            }
                            break;
                        }
                        string[] strArray2 = new string[] { "In den TA-Pool stellen", "Ablösung einreichen", "Ablösung ändern" };
                        if (!this.IdentifySite(strArray2))
                        {
                            this.ActualStep++;
                            break;
                        }
                        break;
                    }
                    case 10:
                    {
                        bool flag7 = false;
                        foreach (AbloeseData data4 in this.AbloeseListe)
                        {
                            if (!data4.Fehler & !data4.Done)
                            {
                                flag7 = true;
                                break;
                            }
                        }
                        if (!flag7)
                        {
                            this.txtStatus.Font = new Font(FontFamily.GenericSansSerif, 10f, FontStyle.Bold);
                            this.TheTimer.Enabled = false;
                            this.ProgressImage.Visible = false;
                            this.AbortButton.Text = "Schließen";
                            if (!this.AlwaysVisible)
                            {
                                this.lstAbloesen.Visible = true;
                                this.webB.Visible = false;
                            }
                            if (!MySettings.MySettingsProperty.UseTAPool)
                            {
                                this.txtStatus.Text = "Ablösevorgang abgeschloßen!";
                            }
                            else
                            {
                                this.txtStatus.Text = "Ablösevorgang abgeschloßen! - Bitte erneut anmelden und TA-Pool unterschreiben.";
                            }
                            HtmlElementCollection elements9 = this.webB.Document.All["leftNavigation"].GetElementsByTagName("a");
                            int num20 = elements9.Count - 1;
                            for (int m = 0; m <= num20; m++)
                            {
                                if (elements9[m].InnerText == "Abmelden")
                                {
                                    elements9[m].InvokeMember("click");
                                    bool flag8 = true;
                                    while (flag8)
                                    {
                                        flag8 = false;
                                        if (this.webB.IsBusy | (this.webB.ReadyState != WebBrowserReadyState.Complete))
                                        {
                                            flag8 = true;
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                HtmlElementCollection elements10 = this.webB.Document.All["leftNavigation"].GetElementsByTagName("a");
                                int num21 = elements10.Count - 1;
                                for (int n = 0; n <= num21; n++)
                                {
                                    if (elements10[n].InnerText == "Vertragsmanagement")
                                    {
                                        this.ActualStep = 4;
                                        elements10[n].InvokeMember("click");
                                        return;
                                    }
                                }
                            }
                            catch (NullReferenceException exception11)
                            {
                                ProjectData.SetProjectError(exception11);
                                NullReferenceException exception6 = exception11;
                                this.ShowUnexpectedSiteError(exception6);
                                ProjectData.ClearProjectError();
                            }
                        }
                        return;
                    }
                }
            }
        }

        private void webB_Starting_Navigation(object sender, WebBrowserNavigatingEventArgs e)
        {
            if (!this.AlwaysVisible)
            {
                this.webB.Visible = false;
                this.lstAbloesen.Visible = true;
            }
            if (this.AlwaysVisible)
            {
                this.webB.Visible = true;
                this.lstAbloesen.Visible = false;
            }
        }

        private Button AbortButton;
      

        private ListView lstAbloesen;

        private ProgressBar ProgressImage;

        public Timer TheTimer;

        private Label txtDebug;

        private Label txtStatus;

        private WebBrowser webB;
    }
}

